package biz.datalk.industrialland.common.util;

import org.apache.commons.lang3.exception.ExceptionUtils;

/**
 * 异常工具类
 *
 * @author tarofang@163.com
 * @date 2020-01-14
 *
 */
public class ExceptionUtil extends ExceptionUtils {

    /**
     * get root cause
     *
     *
     * @param throwable 异常
     * @return root cause 存在 返回 root cause 否则返回本身
     */
    public static Throwable getRootCauseWithSelf(final Throwable throwable) {
        Throwable rootCause = getRootCause(throwable);
        return rootCause == null ? throwable : rootCause;
    }

    /**
     * get root cause
     *
     * @param throwable 异常
     * @param defaultEx 默认异常
     * @return root cuase 存在 返回 root cause 否则返回 defaultEx
     */
    public static Throwable getRootCauseWithDef(final Throwable throwable, final Throwable defaultEx) {
        Throwable rootCause = getRootCause(throwable);
        return rootCause == null ? defaultEx : rootCause;
    }


}
